export const PHONE = /^1\d{10}$/;

/*
* DateFormat
* */

const DEFAULT_FORMAT = 'yyyy-MM-dd hh:mm:ss';
const padNum = n => (n < 10 ? '0' : '') + n;

export const DateFormat = {
    format(d = Date.now(), format = DEFAULT_FORMAT){
        if(!_.isNumber(d)){
            return '';
        }
        if(/^\s+$/.test(format)){
            format = DEFAULT_FORMAT;
        }
        d = new Date(d);
        var y = d.getFullYear(),
            M = padNum(d.getMonth() + 1),
            D = padNum(d.getDate()),
            h = padNum(d.getHours()),
            m = padNum(d.getMinutes()),
            s = padNum(d.getSeconds());
        return format.replace(/yyyy/g, y)
            .replace(/MM/g, M)
            .replace(/dd/g, D)
            .replace(/hh/g, h)
            .replace(/mm/g, m)
            .replace(/ss/g, s);
    }
};

